<?php

include "../../lib/start.php";

check_session();
check_permission(ADM_PERM);

// estraggo le news
if(!isset($_REQUEST['offset']))
    $offset = 0;
else
    $offset = $_REQUEST['offset'];

$limit = 15;

$sel_news = "SELECT id_news, abstract, data, testo, ora, utenti.nome AS nome, utenti.cognome AS cg FROM news, utenti WHERE news.utente = utenti.uid ORDER BY data DESC, id_news DESC ";

if(!isset($_GET['second'])){
	try{
    	$res_news = $db->executeQuery($sel_news);
	} catch (MySQLException $ex){
		$ex->redirect();
	}
    //print $sel_links;
    $count = $res_news->num_rows;
    $_SESSION['count_news'] = $count;
}
else{
    $sel_news .= "LIMIT $limit OFFSET $offset";
    $res_news = $db->execute($sel_news);
}

if($offset == 0)
    $page = 1;
else
    $page = ($offset / $limit) + 1;

$pagine = ceil($_SESSION['count_news'] / $limit);
if($pagine < 1)
    $pagine = 1;
    
// dati per la paginazione (navigate.php)
$colspan = 3;
$link = basename($_SERVER['PHP_SELF']);
$count_name = "count_news";
$row_class = "admin_row";

include "news.html.php";


?>